package com.health.medicine.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.api.model.transporter.TransporterRegisterRequest;
import com.health.common.model.vo.UserKeyVO;
import com.health.medicine.model.dto.medicine.TransportGoodsRequest;
import com.health.medicine.model.dto.transporter.TransportGoodsArrivedRequest;
import com.health.medicine.model.dto.transporter.TransportVehiclesRequest;
import com.health.medicine.model.entity.TransportRecords;
import com.health.medicine.model.entity.TransportUnitVehicles;
import com.health.medicine.service.TransportunitService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.fisco.bcos.sdk.v3.codec.ContractCodecException;
import org.fisco.bcos.sdk.v3.transaction.model.exception.TransactionBaseException;
import org.springframework.web.bind.annotation.*;

import static com.health.common.constant.UserRoleConstant.TRANSPORTER;

/**
 * @author zhexueqi
 * @ClassName TransportController
 * @since 2024/8/30    16:33
 */
@RestController
@RequestMapping("/transport")
public class TransportController {

    @Resource
    private TransportunitService transportunitService;

    /**
     * 添加运输商用户
     *
     * @return 添加成功
     */
    @PostMapping(value = "/createTransporterToMysql")
    public Boolean createTransporterToMysql(@RequestBody TransporterRegisterRequest transactionRegisterRequest) {
        return transportunitService.createTransporterToMysql(transactionRegisterRequest);
    }

    @PostMapping("/createTransporter")
    @Operation(summary = "运输商注册")
    public void createTransporter(@RequestBody UserKeyVO userKeyVO, @RequestParam("userAccount") String userAccount) throws TransactionBaseException, ContractCodecException {
        transportunitService.createTransporter(userKeyVO, userAccount);
    }

    /**
     * 添加车辆信息
     *
     * @return 添加成功
     */
    @PostMapping(value = "/createVehicle")
    @Operation(summary = "添加车辆信息")
    @SaCheckRole(TRANSPORTER)
    public Boolean createVehicle(@RequestBody @Valid TransportVehiclesRequest transportVehiclesRequest) {
        return transportunitService.createVehicle(transportVehiclesRequest);
    }

    /**
     * 查看运输商的车辆信息
     *
     * @return 车辆信息
     */
    @GetMapping(value = "/getMyVehiclesList")
    @Operation(summary = "查看运输商的车辆信息")
    @SaCheckRole(TRANSPORTER)
    public Page<TransportUnitVehicles> getTransportVehicles(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                                            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                                            HttpServletRequest request) {
        return transportunitService.getTransportVehicles(pageNum, pageSize, request);
    }


    /**
     * 查看自己需要运输的货物
     *
     * @return 货物信息
     */
    @GetMapping(value = "/getTransportGoods")
    @Operation(summary = "查看自己需要运输的货物")
    @SaCheckRole(TRANSPORTER)
    public Page<TransportRecords> getTransportGoods(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                                    @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                                    HttpServletRequest request) {

        return transportunitService.getTransportGoods(pageNum, pageSize, request);
    }

    /**
     * 运输货物
     *
     * @param transportGoodsRequest 运输信息
     * @return 添加信息成功
     */
    @PostMapping(value = "/transportGoods")
    @Operation(summary = "运输货物")
    @SaCheckRole(TRANSPORTER)
    public Boolean transportGoods(@RequestBody @Valid TransportGoodsRequest transportGoodsRequest) throws TransactionBaseException, ContractCodecException {
        return transportunitService.transportGoods(transportGoodsRequest);
    }

    /**
     * 运输货物到达
     *
     * @param transportGoodsArrivedRequest 运输信息
     * @return 货物到达成功
     */
    @PostMapping(value = "/transportGoodsArrived")
    @Operation(summary = "运输货物到达")
    @SaCheckRole(TRANSPORTER)
    public Boolean transportGoodsArrived(@RequestBody @Valid TransportGoodsArrivedRequest transportGoodsArrivedRequest) throws TransactionBaseException, ContractCodecException {
        return transportunitService.transportGoodsArrived(transportGoodsArrivedRequest);
    }


}
